package com.njbdqn.ALi.zjg.dao;

import java.util.List;

import org.njbdqn.ali.database.SqlTemplate;

import com.njbdqn.ALi.zjg.entity.PageHelper;
import com.njbdqn.ALi.zjg.vo.ReplyVO;

public class ReplyDAO {
	private SqlTemplate template;
	private PageHelper helper;
	public ReplyDAO(){
		template = new SqlTemplate();
		helper = new PageHelper();
	}
	public List<ReplyVO> findAll(int account){
		String sql="select u.userimg,u.nickname, b.book_name, c.commentcontent, c.commenttime "
				+ " from userinfos u,books b,comment a inner join comment c on a.commentid = "
				+ " c.replyid where u.account=c.account=? and b.book_id=c.book_id order by "
				+ " commenttime desc limit 0,10";
		return template.resultToArray(sql, new Object[]{account}, ReplyVO.class);
	}
	public PageHelper findPage(int cp,int pageSize,int account){
		helper.setPage(cp);
		helper.setSize(pageSize);
		String sql="select c.commentid,u.userimg,u.nickname, b.book_name, c.commentcontent, "
				+ " c.commenttime from userinfos u,books b,comment a inner join comment c "
				+ " on a.commentid = c.replyid where u.account=c.account=? and b.book_id=c.book_id "
				+ " order by  commenttime desc ";
		return helper.getBean(sql, new Object[]{account}, ReplyVO.class);
	}
}
